Skip to content

DM-55432 - #289

Open
BrunoSanchez wants to merge 3 commits into
mainfrom
tickets/DM-55432
Open

DM-55432#289
BrunoSanchez wants to merge 3 commits into
mainfrom
tickets/DM-55432

Conversation

@BrunoSanchez

Copy link
Copy Markdown
Member

Add optional blended fakes to catalog creation tool in AP

@isullivan isullivan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few major issues to highlight:

  • check the intended indentation at a few places I point out. I think there are important lines of code that are only executed in one branch of if/else statements, and they should probably apply to either branch.
  • The delta_ra factors need a cos(dec) factor in order to describe circular distributions on the sky.
  • I am worried that columns of the Pandas dataframe are being turned into masked arrays, and later coerced to the correct data type. If so, this could give undefined values in the final catalog for those columns,

Comment on lines +843 to +847
blended_fakes["injection_id"] = self._make_unique_injection_ids(
len(blended_fakes),
used_ids=catalog["injection_id"],
)
catalog = vstack([catalog, blended_fakes])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines need to be de-indented! If fracHostedBlendedFakes=0, then non-hosted blended fakes are created, but never added to catalog.

blended_fakes["host_ra"] = blended_fakes["ra"]
blended_fakes["host_dec"] = blended_fakes["dec"]

blended_fakes["ra"] += blended_fakes["delta_ra"] / 3600.0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs a cos(dec) factor.

rng, n_star_hosted_blended_fakes
)

ra_ssi = ra_hosts + delta_ra / 3600.0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this delta_ra also needs a cos(dec) factor.

variable_fakes["isVariable"] = True

catalog = vstack([catalog, variable_fakes])
catalog["isBlended"] = False

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This syntax is used in a lot of other places, but since catalog is Pandas I am worried that setting = False will turn this column into a masked array. Please double-check the type of the column at this point in execution (just a print statement in a test should do).

Comment on lines +849 to +860
if len(catalog) > len(np.unique(catalog["injection_id"])):
self.log.warning("Duplicate injection IDs detected after catalog assembly; reassigning them.")
old_injection_ids = np.asarray(catalog["injection_id"], dtype=np.int64)
new_injection_ids = self._make_unique_injection_ids(len(catalog))
# re-assign fresh injection ids
catalog["injection_id"] = new_injection_ids
if "twin_id" in catalog.colnames:
id_map = {old_id: new_id for old_id, new_id in zip(old_injection_ids, new_injection_ids)}
catalog["twin_id"] = np.asarray(
[id_map.get(int(twin_id), int(twin_id)) for twin_id in catalog["twin_id"]],
dtype=np.int64,
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this block is also indented one level too far, since it is now inside if self.config.doAddBlendedFakes but I think it could be run in either case.

Comment on lines +869 to +870
catalog["host_ra"] = catalog["host_ra"].value
catalog["host_dec"] = catalog["host_dec"].value

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might need an additional check - I don't think it is guaranteed that host_ra and host_dec are present at this point.

flagCut &= ~sourceCat['base_PixelFlags_flag']

extendednessCut = sourceCat['base_ClassificationSizeExtendedness_value'] < 0.9
extendednessCut &= sourceCat['base_ClassificationExtendedness_value'] != 1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you want extendednessCut &= sourceCat['base_ClassificationExtendedness_value'] == 0 here. != 1 would accept corrupt data, such as NaN.

return 0

cap = n_hosts * self.config.maxHostedBlendedFakesPerHost
if self.config.maxHostedBlendedFakesTotal > 0:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An edge case, but if someone set self.config.maxHostedBlendedFakesTotal=0 intending to use that to disable adding hosted blended fakes, it would actually do the opposite and disable the check and cap.

if self.config.fracHostedBlendedFakes > 0:
hostcatalog = photoCalib.calibrateCatalog(sourceCat).asAstropy()
star_hosts = self.select_host_stars(hostcatalog)
# if len(star_hosts) is less than the blended fakes, then use replacement

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment says "... then use replacement", but I don't see that happening. Is the comment from an older version? Also, note that if the number of hosts is capped, then the total number of blended fakes will be effectively reduced (below fracBlendedFakes).

Comment on lines +482 to +483
('run', '<U62'),
('band', '<U1')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

run and band are added to the schema, but I don't see either set anywhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants